package com.zxbit.uangstore.view;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.zxbit.uangstore.R;

public class UpdateVersionDialog extends Dialog implements View.OnClickListener {

    private View rootView;
    private TextView tv_tile;
    private TextView tv_content;
    private Button confirm_button;
    private NormalClickListener mNormalClickListener;

    private Context context;

    public UpdateVersionDialog(@NonNull Context context) {
        super(context);
        init(context);
    }

    public UpdateVersionDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        init(context);
    }

    protected UpdateVersionDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
        rootView = LayoutInflater.from(context).inflate(R.layout.dialog_update_version_layout, null);
        tv_tile = rootView.findViewById(R.id.tv_tile);
        tv_content = rootView.findViewById(R.id.tv_content);
        confirm_button = rootView.findViewById(R.id.confirm_button);
        setContentView(rootView);
        Window window = getWindow();
        window.setGravity(Gravity.CENTER);
        window.getDecorView().setPadding(0, 0, 0, 0);
        window.setLayout((int) context.getResources().getDimension(R.dimen.x520), WindowManager.LayoutParams.WRAP_CONTENT);//设置横向全屏

        confirm_button.setOnClickListener(this);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }


    public UpdateVersionDialog setTitle(String title) {
        if (tv_tile != null) {
            tv_tile.setText(title);
        }
        return this;
    }


    public UpdateVersionDialog setContent(String contentStr) {
        if (tv_content != null) {
            tv_content.setText(contentStr);
        }
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.confirm_button:
                if (mNormalClickListener != null) {
                    mNormalClickListener.onConfirmClick();
                }
                break;
        }
    }


    public UpdateVersionDialog setNormalClickListener(NormalClickListener listener) {
        mNormalClickListener = listener;
        return this;
    }

    public interface NormalClickListener {
        void onConfirmClick();
    }
}
